package com.demo.las.controller;

import com.demo.las.dto.ApiResponse;
import com.demo.las.service.StudyAccountingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Map;

@RestController
@RequestMapping("/api/study-accounting")
@CrossOrigin(origins = "*")
public class StudyAccountingController {

    @Autowired
    private StudyAccountingService studyAccountingService;

    @GetMapping("/balance-sheet")
    public ApiResponse<StudyAccountingService.BalanceSheet> getBalanceSheet(@RequestParam Long userId) {
        StudyAccountingService.BalanceSheet balanceSheet = studyAccountingService.calculateBalanceSheet(userId);
        return ApiResponse.success(balanceSheet);
    }

    @GetMapping("/income-statement")
    public ApiResponse<StudyAccountingService.IncomeStatement> getIncomeStatement(
            @RequestParam Long userId,
            @RequestParam LocalDate startDate,
            @RequestParam LocalDate endDate) {
        StudyAccountingService.IncomeStatement incomeStatement = studyAccountingService.calculateIncomeStatement(userId, startDate, endDate);
        return ApiResponse.success(incomeStatement);
    }

    @GetMapping("/cash-flow")
    public ApiResponse<StudyAccountingService.CashFlowStatement> getCashFlowStatement(
            @RequestParam Long userId,
            @RequestParam LocalDate startDate,
            @RequestParam LocalDate endDate) {
        StudyAccountingService.CashFlowStatement cashFlow = studyAccountingService.calculateCashFlowStatement(userId, startDate, endDate);
        return ApiResponse.success(cashFlow);
    }

    @GetMapping("/financial-report")
    public ApiResponse<Map<String, Object>> getFinancialReport(
            @RequestParam Long userId,
            @RequestParam LocalDate startDate,
            @RequestParam LocalDate endDate) {
        Map<String, Object> report = studyAccountingService.generateLearningReport(userId, startDate, endDate);
        return ApiResponse.success(report);
    }
}




